package com.example.dailyrecord.entity;

import com.example.dailyrecord.util.FunctionUtils;
import com.example.dailyrecord.util.IDUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

@Data
@ApiModel("记录")
public class Record {
    @ApiModelProperty("备注")
    private String bz;
    @ApiModelProperty("")
    private String id;
    @ApiModelProperty("结束时间")
    private String jssj;
    @ApiModelProperty("科目")
    private String km;
    @ApiModelProperty("开始时间")
    private String kssj;
    @ApiModelProperty("用户id")
    private String uid;
    @ApiModelProperty("学习时长")
    private int duration;
    public static final String TABLE_NAME = "record";
    public static final String[] ALL_COLUMNS = {"`bz`", "`duration`", "`id`", "`jssj`", "`km`", "`kssj`", "`uid`"};
    public static final String BZ_COLUMN = "`bz`";
    public static final String BZ_NAME = "bz";
    public static final String DURATION_COLUMN = "`duration`";
    public static final String DURATION_NAME = "duration";
    public static final String ID_COLUMN = "`id`";
    public static final String ID_NAME = "id";
    public static final String JSSJ_COLUMN = "`jssj`";
    public static final String JSSJ_NAME = "jssj";
    public static final String KM_COLUMN = "`km`";
    public static final String KM_NAME = "km";
    public static final String KSSJ_COLUMN = "`kssj`";
    public static final String KSSJ_NAME = "kssj";
    public static final String UID_COLUMN = "`uid`";
    public static final String UID_NAME = "uid";

    public static Record getInstance(String email, String km, String bz) {
        return getInstance(email, FunctionUtils.getNowTime(), null, km, bz);
    }

    public static Record getInstance(String email, String kssj, String jssj, String km, String bz) {
        Record record = new Record();
        record.setId(IDUtils.getStringID());
        record.setKssj(kssj);
        record.setJssj(jssj);
        record.setKm(km);
        record.setBz(bz);
        record.setUid(email);
        return record;
    }

    public String[] getKms() {
        if (StringUtils.isEmpty(this.km)) {
            return new String[]{};
        }
        if (this.km.contains(FunctionUtils.COMMA)) {
            return this.km.split(FunctionUtils.COMMA);
        }
        return new String[]{this.km};
    }

}
